package com.hsy.crm.web.config;

import com.hsy.crm.web.web.DemoVo;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

@Configuration
public class RedisConfig {

    @Bean("xxxRedisTemplate")
    public RedisTemplate<String, DemoVo> xxxRedisTemplate(RedisConnectionFactory redisConnectionFactory) {
        RedisTemplate<String, DemoVo> template = new RedisTemplate();

        Jackson2JsonRedisSerializer<DemoVo> j = new Jackson2JsonRedisSerializer<>(DemoVo.class);

        template.setValueSerializer(j);
        template.setHashValueSerializer(j);

        template.setKeySerializer(new StringRedisSerializer());
        template.setHashKeySerializer(new StringRedisSerializer());

        template.setConnectionFactory(redisConnectionFactory);
        return template;
    }

    @Bean("cacheRedisTemplate")
    public RedisTemplate<String, String> cacheRedisTemplate(RedisConnectionFactory redisConnectionFactory) {
        RedisTemplate<String, String> template = new RedisTemplate();
        template.setValueSerializer(new StringRedisSerializer());
        template.setHashValueSerializer(new StringRedisSerializer());
        template.setKeySerializer(new StringRedisSerializer());
        template.setHashKeySerializer(new StringRedisSerializer());
        template.setConnectionFactory(redisConnectionFactory);
        return template;
    }

}
